package com.qk.controller;

import com.qk.commom.Result;
import com.qk.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Slf4j
@RestController
public class UploadController {



    /*@PostMapping("/upload")
        public Result upload(String name, Integer age, MultipartFile  file) throws Exception {
            log.info("{},{},{}",name,age,file);
            String filenName=file.getOriginalFilename();
            String suffix= filenName.substring(filenName.lastIndexOf("."));
            String newFileName= UUID.randomUUID().toString()+suffix;
            file.transferTo(new File("F:\\a\\"+newFileName));
            return Result.success();
        }*/



    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws Exception {
        String imageName= image.getOriginalFilename();
        String suff=imageName.substring(imageName.lastIndexOf("."));
        String newImageName=UUID.randomUUID().toString()+suff;
        String url=aliyunOSSOperator.upload(image.getBytes(),newImageName);
        return Result.success(url);
    }
}
